package com.zyz.L_泛型.泛型使用;

/**
 * @author: vick
 * @Date: 2025/4/2
 * @Description:
 * @version: 1.0
 */
public class Rectangle implements Comparable<Rectangle>{
    private double length;
    private double width;

    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }

    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        this.length = length;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    @Override
    public String toString() {
        return "Rectangle{" +
                "length=" + length +
                ", width=" + width +
                '}';
    }

    public double area() {
        return length * width;
    }

    public double perimeter() {
        return 2 * (length + width);
    }

    @Override
    public int compareTo(Rectangle o) {
        //比较面积
        int compare = Double.compare(area(), o.area());

        return compare !=0 ? compare : Double.compare(perimeter(), o.perimeter());
    }
}
